Skip to content

fix: Fix langfuse tracer when input messages is None#3324

Merged
sjrl merged 2 commits into
mainfrom
fix-langfuse-messages-non
May 18, 2026
Merged

fix: Fix langfuse tracer when input messages is None#3324
sjrl merged 2 commits into
mainfrom
fix-langfuse-messages-non

Conversation

@sjrl
Copy link
Copy Markdown
Contributor

@sjrl sjrl commented May 18, 2026

Related Issues

Proposed Changes:

The LLM component accepts messages=None as valid input which can break the Langfuse Tracer since it always assumes that if messages is present that it's always a list[ChatMessage]. This PR updates to handle the None case.

We also add the same guard for replies returning as None. This is not a known case but done for safety.

How did you test it?

Added new unit tests.

Notes for the reviewer

Checklist

@sjrl sjrl requested a review from a team as a code owner May 18, 2026 11:07
@sjrl sjrl requested review from anakin87 and removed request for a team May 18, 2026 11:07
@sjrl sjrl self-assigned this May 18, 2026
@github-actions github-actions Bot added integration:langfuse type:documentation Improvements or additions to documentation labels May 18, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Coverage report (langfuse)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  integrations/langfuse/src/haystack_integrations/tracing/langfuse
  tracer.py 90
Project Total  

This report was generated by python-coverage-comment-action

if key.endswith(".input"):
if "messages" in value:
messages = [m.to_openai_dict_format(require_tool_call_ids=False) for m in value["messages"]]
messages = [m.to_openai_dict_format(require_tool_call_ids=False) for m in (value.get("messages") or [])]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do value.get("messages") or [] to catch the case that messages key is present in value but it returns None. Doing value.get("messages", []) would not catch it since the back up [] only occurs if messages is missing.

Copy link
Copy Markdown
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

(I'm not a big fan of the LLM component 😃)

@sjrl sjrl merged commit 6c23d4d into main May 18, 2026
16 checks passed
@sjrl sjrl deleted the fix-langfuse-messages-non branch May 18, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration:langfuse type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants